<?php

namespace app\command;

use app\ArrayToolkit;
use app\client\WeChatClient;
use app\logic\Message;
use app\logic\User;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class SendMessage extends Command
{
    protected $type = "SendMessage";

    protected $weChatClient = null;
    protected function configure()
    {
        parent::configure();
        $this->setName('send:SendMessage')
            ->addArgument('body', Argument::REQUIRED, '需要发送的值')
            ->setDescription('sync weChat User Data');
    }

    protected function execute(Input $input, Output $output)
    {
        $body = trim($input->getArgument('body'));
        if (empty($body)) {
            $output->info('success');
        }

        try {
            list($templateId, $userOpenId) = explode(':', $body);
            $this->getMessageLogic()->sendWeChatMessage($templateId, $userOpenId);
            $output->info('success');
        } catch (\Exception $e) {
            $output->error('error');
        }
    }


    /**
     * @return Message
     */
    protected function getMessageLogic()
    {
        return app('logic')->logic('Message');
    }
}
